package com.sky.mapper;

import com.sky.entity.WalletTransactions;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.sky.vo.WalletTransactionsVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * Mapper 接口
 * </p>
 *
 * @author GHOSTER by RemSynch
 * @since 2024-10-24
 */
@Mapper
public interface WalletTransactionsMapper extends BaseMapper<WalletTransactions> {

    /**
     * SELECT
     * sa.id as uid,
     * wt.transaction_id,
     * wt.balance,
     * wt.amount,
     * wt.created_at as wt_time
     * FROM
     * sub_accounts sa
     * INNER JOIN wallet_transactions wt ON sa.id = wt.user_id
     */
    @Select("select wt.user_id,sa.username,sa.phone,wt.transaction_id,wt.balance,wt.amount,wt.created_at,wt.description,wt.transaction_type" +
            " from sub_accounts sa INNER JOIN wallet_transactions wt ON sa.id = wt.user_id order by wt.created_at desc ")
    List<WalletTransactionsVO> listWT();

    @Select("select wt.user_id,sa.username,sa.phone,wt.transaction_id,wt.balance,wt.amount,wt.created_at,wt.description,wt.transaction_type" +
            " from sub_accounts sa INNER JOIN wallet_transactions wt ON sa.id = wt.user_id WHERE wt.userId = #{userId} order by wt.created_at desc ")
    List<WalletTransactionsVO> listWTByUserId(String userId);
}


